import { cloneDeep, findIndex, flattenDeep, uniqueId } from 'lodash'
import { getCurrentInstance, reactive } from 'vue'
import { Messages, confirm } from '@Config/config'
import { message } from 'ant-design-vue'
import { tagList } from '@Config/server/api'
import { useRoute } from 'vue-router'
import {
  IconHuiShouZhan,
  IconShanChu,
  iconYiDong,
  IconXiaZai,
  IconShouCangJia,
  IconBiaoQian,
  IconYiFaBu,
} from '@Assets/fonts/svg'
import { useWin } from '@Hooks/win'
import BatchTags from '@Page/my/components/tag/batch'
import Tags from '@Page/my/components/tag'
export const instanceFn = () => {
  let { proxy } = getCurrentInstance()
  let route = useRoute()
  //操作按钮,主菜单和右键菜单
  let operMenu = () => {
    let _list = [
      {
        label: '批量下载',
        action: () => proxy.downLoad(proxy.tables_selected),

        icon: <IconXiaZai />,
      },
      {
        label: '删除',
        action: proxy.batchReoveFile,
        attr: {
          danger: true,
        },
        icon: <IconShanChu />,
      },
      // {
      //   label: '移到回收站',
      //   action: proxy.batchToTrash,
      //   attr: { danger: true },
      //   icon: <IconHuiShouZhan />,
      // },

      {
        label: '批量移动',
        action: (x) => proxy.batchMove(proxy.isPublic),
        icon: <iconYiDong />,
      },

      {
        label: '批量备份',
        action: (x) => proxy.favorite(proxy.tables_selected.map((x) => x.id)),
        icon: <IconShouCangJia />,
      },
      {
        label: '批量加密',
        action: (x) => proxy.unPublish(proxy.tables_selected),
        icon: <IconYiFaBu />,
      },
    ]
    return _list
  }

  //选择/取消 全部
  let selectAllHandler = (e) => {
    proxy.tableData.data.source.map((x) => {
      x.selected = e.target.checked
    })
  }

  let tagList_filter = reactive({
    // key: 'tagIdList',
    // initValue: [],
    // source: [],
    // uiType: 'select',
    // col: { span: 12 },
    // formItem: { label: '标签1' },
    // attr: {
    //   placeholder: '搜索标签',
    //   mode: 'multiple',
    //   optionFilterProp: 'label',
    //   allowClear: true,
    //   loading: true,
    //   maxTagCount: 6,
    //   maxTagTextLength: 6,
    // },
  })

  let getTagList = () => {
    //加载查询条件tag
    tagList({ size: 100000, index: 1 }).then((_tags) => {
      tagList_filter.attr.loading = false
      let _r = _tags.data.records.map((x) => {
        return x.child.map((xx) => {
          return {
            ...xx,
            label: x.name + '-' + xx.name,
            value: String(xx.id),
          }
        })
      })
      tagList_filter.source = flattenDeep(_r)
    })
  }

  return {
    operMenu,
    selectAllHandler,
    getTagList,
    tagList_filter,
  }
}
